package com.bgt.springboot.first.service;

import com.bgt.springboot.first.repository.UserRepository;
import com.bgt.springboot.first.utils.Page;
import com.bgt.springboot.first.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by bgt on 2017/4/18.
 */
@Service
public class UserService {
    @Autowired
    private UserRepository userRepository;
    @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public void add2(User user){
        userRepository.save(user);
    }
    @Transactional(value = "transactionDManager",isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)
    public void add(User user){
        userRepository.save(user);
    }

    public List<User> findById(Integer id){
        return userRepository.findById(id);
    }
    public List<User> findById2(Integer id){
        return userRepository.findById2(id);
    }
    public Page<User> findAll(Page<com.bgt.springboot.first.vo.User> page2){
        page2.setResults(userRepository.findAll());
        page2.setTotalRecords(userRepository.countAll());
        return page2;
    }
}
